package servlet;

import dao.UserDao;

import javax.servlet.*;
import javax.servlet.http.*;
import javax.servlet.annotation.*;
import java.io.IOException;
import java.io.PrintWriter;

@WebServlet("/nickServlet")
public class NickServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        req.setCharacterEncoding("utf-8");
        resp.setContentType("text/html;charset=utf-8");
        System.out.println("get...");
        String nick = req.getParameter("nick");
        System.out.println(nick);

        PrintWriter writer = resp.getWriter();
        UserDao userDao = new UserDao();
        System.out.println(userDao.checkNick(nick));
        if (userDao.checkNick(nick)) {
            writer.write("no");
        } else {
            writer.write("yes");
        }
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        this.doGet(req, resp);
    }
}
